import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/Login.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: login
  },
  {
    path: '/home',
    name: 'home',
    redirect: '/user',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/home'),
    children: [
      {
        path: '/user',
        name: '首页',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/user')
      },
      {
        path: '/users',
        name: '用户管理',
        meta: {
          roles: ['admin']
        },
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/users')
      },
      {
        path: '/echart',
        name: '数据视图',
        meta: {
          roles: ['admin']
        },
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/echart')
      },
      {
        path: '/write',
        name: '新增文章',
        meta: {
          roles: ['admin']
        },
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/writeAnthor')
      },
      {
        path: '/readbook',
        name: '查看文章',
        meta: {
          roles: ['admin']
        },
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/readbook')
      },
      {
        path: '/work',
        name: '工作台',
        meta: {
          roles: ['lizbjyw']
        },
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/work')
      },
      {
        path: '/listen',
        name: '留言板',
        meta: {
          roles: ['admin']
        },
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/listen')
      },
      {
        path: '/personTarget',
        name: '个人目标',
        meta: {
          roles: ['admin']
        },
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/personTarget')
      }
    ]
  }
]

const router = new VueRouter({
  routes
})
const routerRePush = VueRouter.prototype.push
VueRouter.prototype.push = function (location) {
  return routerRePush.call(this, location).catch(error => error)
}
export default router
